package com.tinywind.admin.module.system.controller;

import com.tinywind.admin.common.base.BaseController;
import com.tinywind.admin.common.base.BaseResult;
import com.tinywind.admin.common.utils.DictUtils;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuxingyu01
 * @date 2022-01-15-21:32
 **/
@RestController
@RequestMapping("/system/dict")
public class SysDictController extends BaseController {
    final static Logger logger = LoggerFactory.getLogger(SysDictController.class);


    /**
     * 获取指定的枚举列表
     *
     * @param dictCode
     * @return
     */
    @ApiOperation(value = "获取指定的枚举列表", notes = "获取指定的枚举列表")
    @RequestMapping(value = "/getDictList", method = RequestMethod.GET)
    public BaseResult delete(@RequestParam(value = "dictCode") String dictCode) {
        List<Map<String, String>> dictList = DictUtils.getDictList(dictCode);
        if (dictList != null && !dictList.isEmpty()) {
            List<Map<String, String>> dictList2 = new ArrayList<>();
            dictList.forEach(item -> {
                Map<String, String> item2 = new HashMap<>();
                item2.put("value", item.get("dict_key"));
                item2.put("label", item.get("dict_value"));
                dictList2.add(item2);
            });

            return BaseResult.success("获取成功!", dictList2);
        } else {
            return BaseResult.failure("获取成功，dictCode不存在！");
        }
    }

}
